var util = require("util.js")

function post(url, bizParams, successCallBack, failCallBack) {
  var systemParams = wx.getSystemInfoSync();
  wx.showNavigationBarLoading();
  wx.request({
    url: url,
    method: 'POST',
    data: {
      loginSessionId: wx.getStorageSync('loginSessionId'),
      systemParams: JSON.stringify(systemParams),
      bizParams: JSON.stringify(bizParams)
    },
    header: {
      'content-type': 'application/x-www-form-urlencoded'
    },
    success: function(res) {
      console.log("http url:" + url);
      console.log(res.data);
      wx.hideNavigationBarLoading();
      if ('0' == res.data.code) {
        successCallBack(res);
      } else {
        if (!util.isNull(failCallBack)) {
          failCallBack(res);
        } else {
          wx.showToast({
            title: res.data.message,
            icon: 'none',
            duration: 2000,
            mask: true
          })
        }
      }
    },
    fail: function(res) {
      wx.hideNavigationBarLoading();
      wx.showToast({
        title: "网络异常",
        icon: "none",
        duration: 2000
      })
    }
  })

}

module.exports = {
  post: post
}